package se.webbzon.oschi01.hash;

import java.io.IOException;
import java.io.OutputStream;

public class MD5OutputStream extends OutputStream {
	
	// The MD5 instance associated with this outputs stream
	private final MD5 md5;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public MD5OutputStream() {
		md5 = new MD5();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the MD5-sum calculated by this instance. **/
	public byte[] sum() {
		return md5.sum();
	}

	@Override public void write(int b) throws IOException {
		md5.addByte((byte) b);
	}

	@Override public void write(byte[] b, int off, int len) throws IOException {
		md5.addBytes(b, off, len);
	}

}
